package com.clkj.xiuzheng.controller;

import com.clkj.xiuzheng.pojo.Customer;
import com.clkj.xiuzheng.pojo.OutStock;
import com.clkj.xiuzheng.pojo.OutStockItem;
import com.clkj.xiuzheng.pojo.common.Result;
import com.clkj.xiuzheng.pojo.common.StatusCode;
import com.clkj.xiuzheng.service.OutStockService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yawang
 * @create 2024/04/18 15:25:56
 **/
@RestController
@RequestMapping(value = "/outStock")
@Api(value = "/outStock", tags = {"销售出库"})
@CrossOrigin
public class OutStockController {
    @Autowired
    private OutStockService outStockService;

    @ApiOperation(value = "添加销售出库")
    @PostMapping("/addOutStock")
    public Result addOutStock( @RequestBody OutStock outStock){
        try {
            outStockService.addOutStock(outStock);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }

    @ApiOperation(value = "获取客湖订单信息")
    @PostMapping("/listCustomerOutStock")
    public Result listCustomerOutStock(Integer customerId){
        try {
           List<OutStock> outStockList =  outStockService.listCustomerOutStock(customerId);
            return new Result(true, StatusCode.OK,"查询成功",outStockList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "单据详情")
    @PostMapping("/outStockDetail")
    public Result outStockDetail(Integer outId){
        try {
            List<OutStockItem> itemList =  outStockService.outStockDetail(outId);
            return new Result(true, StatusCode.OK,"查询成功",itemList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "获取业务员近7天销售记录")
    @PostMapping("/outStockListBySeven")
    public Result outStockListBySeven(Integer userId){
        try {
            List<OutStock> outStockList =  outStockService.outStockListBySeven(userId);
            return new Result(true, StatusCode.OK,"查询成功",outStockList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "获取销售出库主表信息")
    @PostMapping("/getOutStock")
    public Result getOutStock(@RequestParam Integer pageSize,
                              @RequestParam Integer pageNum,Integer companyId){
        try {
            PageInfo pageInfo =  outStockService.getOutStock(pageSize,pageNum,companyId);
            return new Result(true, StatusCode.OK,"查询成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }

    @ApiOperation(value = "获取销售出库分表信息")
    @PostMapping("/getOutStockItem")
    public Result getOutStockItem(@RequestParam Integer pageSize,
                                  @RequestParam Integer pageNum,
                                  @RequestParam Integer outId){
        try {
            PageInfo pageInfo =  outStockService.getOutStockItem(pageSize,pageNum,outId);
            return new Result(true, StatusCode.OK,"查询成功",pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"查询失败");
        }
    }
    @ApiOperation(value = "出库审核")
    @PostMapping("/applyOutStockItem")
    public Result applyOutStockItem(@RequestParam Integer outId){
        try {
            outStockService.applyOutStockItem(outId);
            return new Result(true, StatusCode.OK,"审核成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"审核失败");
        }
    }
    @ApiOperation(value = "销售出库添加物流信息")
    @PostMapping("/addOutStockLogistics")
    public Result addOutStockLogistics(@RequestParam Integer outId,
                                       @RequestParam String logisticsName,
                                       @RequestParam String logisticsNum){
        try {
            outStockService.addOutStockLogistics(outId,logisticsName,logisticsNum);
            return new Result(true, StatusCode.OK,"添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR,"添加失败");
        }
    }





}
